
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>安装 SpatiaLite &#8212; Django 3.2.11.dev 文档</title>
    <link rel="stylesheet" href="../../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../../../../genindex.html" />
    <link rel="search" title="搜索" href="../../../../search.html" />
    <link rel="next" title="GeoDjango Model API" href="../model-api.html" />
    <link rel="prev" title="安装 PostGIS" href="postgis.html" />



 
<script src="../../../../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../../index.html">Django 3.2.11.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="postgis.html" title="安装 PostGIS">previous</a>
     |
    <a href="../../../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="../model-api.html" title="GeoDjango Model API">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-gis-install-spatialite">
            
  <div class="section" id="s-installing-spatialite">
<span id="installing-spatialite"></span><h1>安装 SpatiaLite<a class="headerlink" href="#installing-spatialite" title="永久链接至标题">¶</a></h1>
<p><a class="reference external" href="https://www.gaia-gis.it/fossil/libspatialite/index">SpatiaLite</a> 为 SQLite 增加了空间支持，使其成为一个全功能的空间数据库。</p>
<p>首先，检查是否可以从系统包或二进制文件中安装 SpatiaLite。</p>
<p>For example, on Debian-based distributions that package SpatiaLite 4.3+, try to
install the <code class="docutils literal notranslate"><span class="pre">libsqlite3-mod-spatialite</span></code> package. For older releases install
<code class="docutils literal notranslate"><span class="pre">spatialite-bin</span></code>.</p>
<p>对于 macOS，请按照 <a class="reference internal" href="#spatialite-macos"><span class="std std-ref">下方的说明</span></a>。</p>
<p>对于 Windows，你可以在 <a class="reference external" href="https://www.gaia-gis.it/gaia-sins/">Gaia-SINS</a> 主页上找到二进制文件。</p>
<p>在任何情况下，你都应该能够 <a class="reference internal" href="#spatialite-source"><span class="std std-ref">从源码安装</span></a>。</p>
<div class="section" id="s-installing-from-source">
<span id="s-spatialite-source"></span><span id="installing-from-source"></span><span id="spatialite-source"></span><h2>从源码安装<a class="headerlink" href="#installing-from-source" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="geolibs.html"><span class="doc">GEOS and PROJ</span></a> should be installed
prior to building SpatiaLite.</p>
<div class="section" id="s-sqlite">
<span id="sqlite"></span><h3>SQLite<a class="headerlink" href="#sqlite" title="永久链接至标题">¶</a></h3>
<p>首先检查 SQLite 是否使用 <a class="reference external" href="https://www.sqlite.org/rtree.html">R*Tree 模块</a> 编译。运行 sqlite3 命令行界面，输入以下查询：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sqlite</span><span class="o">&gt;</span> <span class="n">CREATE</span> <span class="n">VIRTUAL</span> <span class="n">TABLE</span> <span class="n">testrtree</span> <span class="n">USING</span> <span class="n">rtree</span><span class="p">(</span><span class="nb">id</span><span class="p">,</span><span class="n">minX</span><span class="p">,</span><span class="n">maxX</span><span class="p">,</span><span class="n">minY</span><span class="p">,</span><span class="n">maxY</span><span class="p">);</span>
</pre></div>
</div>
<p>如果你获得一个错误，你将不得不从源码重新编译 SQLite。否则，请跳过本节。</p>
<p>要从源码安装，请从 <a class="reference external" href="https://www.sqlite.org/download.html">SQLite 下载页面</a> 下载最新的合并源码档案，并解压：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ wget https://www.sqlite.org/YYYY/sqlite-amalgamation-XXX0000.zip
$ unzip sqlite-amalgamation-XXX0000.zip
$ cd sqlite-amalgamation-XXX0000
</pre></div>
</div>
<p>接下来，运行 <code class="docutils literal notranslate"><span class="pre">configure</span></code> 脚本 —— 不过 <code class="docutils literal notranslate"><span class="pre">CFLAGS</span></code> 环境变量需要自定义，以便 SQLite 知道如何构建 R*Tree 模块：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ CFLAGS=&quot;-DSQLITE_ENABLE_RTREE=1&quot; ./configure
$ make
$ sudo make install
$ cd ..
</pre></div>
</div>
</div>
<div class="section" id="s-spatialite-library-libspatialite">
<span id="s-spatialitebuild"></span><span id="spatialite-library-libspatialite"></span><span id="spatialitebuild"></span><h3>SpatiaLite 库（<code class="docutils literal notranslate"><span class="pre">libspatialite</span></code>）<a class="headerlink" href="#spatialite-library-libspatialite" title="永久链接至标题">¶</a></h3>
<p>从 <a class="reference external" href="https://www.gaia-gis.it/gaia-sins/libspatialite-sources/">下载页面</a> 获取最新的 SpatiaLite 库源捆绑包：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ wget https://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-X.Y.Z.tar.gz
$ tar xaf libspatialite-X.Y.Z.tar.gz
$ cd libspatialite-X.Y.Z
$ ./configure
$ make
$ sudo make install
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p>对于从源头构建的 macOS 用户来说，SpatiaLite 库 <em>和</em> 工具需要配置其 <code class="docutils literal notranslate"><span class="pre">target</span></code> ：</p>
<div class="last highlight-default notranslate"><div class="highlight"><pre><span></span>$ ./configure --target=macosx
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="s-macos-specific-instructions">
<span id="s-spatialite-macos"></span><span id="macos-specific-instructions"></span><span id="spatialite-macos"></span><h2>macOS 特定说明<a class="headerlink" href="#macos-specific-instructions" title="永久链接至标题">¶</a></h2>
<p>要安装 SpatiaLite 库和工具，macOS 用户可以选择 <a class="reference internal" href="index.html#kyngchaos"><span class="std std-ref">KyngChaos 包</span></a> 和 <a class="reference external" href="https://brew.sh/">Homebrew</a> 。</p>
<div class="section" id="s-kyngchaos">
<span id="kyngchaos"></span><h3>KyngChaos<a class="headerlink" href="#kyngchaos" title="永久链接至标题">¶</a></h3>
<p>首先，按照 <a class="reference internal" href="index.html#kyngchaos"><span class="std std-ref">KyngChaos 包</span></a> 部分的说明。</p>
<p>在创建 SpatiaLite 数据库时，需要使用 <code class="docutils literal notranslate"><span class="pre">spatialite</span></code> 程序。但是，不要试图从源头编译 SpatiaLite 工具，而是下载 MacOS 的 <a class="reference external" href="https://www.kyngchaos.com/software/frameworks/">SpatiaLite Tools</a> 包，并将 <code class="docutils literal notranslate"><span class="pre">spatialite</span></code> 安装到 <code class="docutils literal notranslate"><span class="pre">PATH</span></code> 中的可用位置。 例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ curl -O https://www.kyngchaos.com/files/software/frameworks/Spatialite_Tools-4.3.zip
$ unzip Spatialite_Tools-4.3.zip
$ cd Spatialite\ Tools/tools
$ sudo cp spatialite /Library/Frameworks/SQLite3.framework/Programs
</pre></div>
</div>
<p>最后，为了让 GeoDjango 能够找到 KyngChaos SpatiaLite 库，在你的 <code class="docutils literal notranslate"><span class="pre">settings.py</span></code> 中添加以下内容：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">SPATIALITE_LIBRARY_PATH</span><span class="o">=</span><span class="s1">&#39;/Library/Frameworks/SQLite3.framework/SQLite3&#39;</span>
</pre></div>
</div>
</div>
<div class="section" id="s-homebrew">
<span id="homebrew"></span><h3>Homebrew<a class="headerlink" href="#homebrew" title="永久链接至标题">¶</a></h3>
<p><a class="reference external" href="https://brew.sh/">Homebrew</a> 代表你处理所有与 SpatiaLite 相关的软件包，包括 SQLite、SpatiaLite、PROJ 和 GEOS。按以下方式安装它们：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ brew update
$ brew install spatialite-tools
$ brew install gdal
</pre></div>
</div>
<p>最后，为了让 GeoDjango 能够找到 SpatiaLite 库，在你的 <code class="docutils literal notranslate"><span class="pre">settings.py</span></code> 中添加以下内容：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">SPATIALITE_LIBRARY_PATH</span><span class="o">=</span><span class="s1">&#39;/usr/local/lib/mod_spatialite.dylib&#39;</span>
</pre></div>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">安装 SpatiaLite</a><ul>
<li><a class="reference internal" href="#installing-from-source">从源码安装</a><ul>
<li><a class="reference internal" href="#sqlite">SQLite</a></li>
<li><a class="reference internal" href="#spatialite-library-libspatialite">SpatiaLite 库（<code class="docutils literal notranslate"><span class="pre">libspatialite</span></code>）</a></li>
</ul>
</li>
<li><a class="reference internal" href="#macos-specific-instructions">macOS 特定说明</a><ul>
<li><a class="reference internal" href="#kyngchaos">KyngChaos</a></li>
<li><a class="reference internal" href="#homebrew">Homebrew</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="postgis.html"
                        title="上一章">安装 PostGIS</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="../model-api.html"
                        title="下一章">GeoDjango Model API</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../../../../_sources/ref/contrib/gis/install/spatialite.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">12月 07, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="postgis.html" title="安装 PostGIS">previous</a>
     |
    <a href="../../../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="../model-api.html" title="GeoDjango Model API">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>